package Dao.impl;

import Dao.BaseDao;
import Dao.OrderDao;
import Dao.OrderItemDao;
import pojo.Order;
import pojo.OrderItem;

import java.util.List;

public class OrderServiceI extends BaseDao implements OrderDao, OrderItemDao{
    @Override
    public void saveOrder(Order order) {
        String sql = "insert into order_book (order_Id,create_time,price,order_status,user_id) values(?,?,?,?,?)";
        updateForOne(sql,order.getOrderId(), order.getCreatetime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select order_id orderId,create_time createtime ,price,order_status status,user_id userId from order_book";
        return queryMore(Order.class,sql);
    }

    @Override
    public void changeOrderStatus(String id, Integer status) {
        String sql = "update order_book set order_status = ? where order_id = ?";
        updateForOne(sql,status,id);
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer userId) {
        String sql = "select order_id orderId,create_time createtime ,price,order_status status,user_id userId " +
                "FROM order_book WHERE user_id = ?";
       return queryMore(Order.class,sql,userId);
    }


    @Override
    public void saveOrderItem(OrderItem order) {
       String sql ="insert into order_item (NAME,`count`,price,totalPrice,order_id) values(?,?,?,?,?)";
       updateForOne(sql,order.getName(),order.getCount(),order.getPrice(),order.getTotalPrice(),order.getOrderId());
    }

    @Override
    public List<OrderItem> queryOrderItemsByOrderId(String id) {
        String sql = "select id,NAME name,`count`,price,totalPrice,order_id orderId from order_item where order_id = ?";
        return  queryMore(OrderItem.class,sql,id);
    }
}
